﻿using M.Warehouse.API.Application.Command.ReservoirsCommand;
using M.Warehouse.Domain;
using M.Warehouse.Repository.WarehouseInterface;
using MediatR;

namespace M.Warehouse.API.Application.CommandHandlers.ReservoirsHandlers
{
    /// <summary>
    /// 返填库区中介者
    /// </summary>
    public class ReservoirsBackfillCommandHandlers : IRequestHandler<ReservoirsBackfillCommand, Reservoirs>
    {
        /// <summary>
        /// 库区接口
        /// </summary>
        private readonly IReservoirsWRepository _repository;
        /// <summary>
        /// 构造函数注入
        /// </summary>
        /// <param name="repository"></param>
        public ReservoirsBackfillCommandHandlers(IReservoirsWRepository repository)
        {
            _repository = repository;
        }
        /// <summary>
        /// 返填库区
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task<Reservoirs> Handle(ReservoirsBackfillCommand request, CancellationToken cancellationToken)
        {
            return (await _repository.GetAllAsync()).Where(x => x.ReservoirId == request.ReservoirId).FirstOrDefault();
        }
    }
}
